import { defineStore } from 'pinia'
import { reactive } from 'vue'
import {
	DATA_MSG,
	requestDelMessageById,
	request_post_update_msgStatus,
	request_post_user_newMessage,
	requestSelectAll
} from '../service/message'

export default defineStore('useMessageStore', () => {
	const initMsgData = reactive({
		allMessage: [],
		selectUserData: []
	})
	// 删除消息
	const delMessageById = async (messageId: number) => {
		const res = await requestDelMessageById(messageId)
		console.log(res, "| res");
	}
	
	// 查询所有信息
	const selectAllMessage = async () => {
		const res = await requestSelectAll()
		initMsgData.allMessage = res?.data
	}
	
	// 查询某个用户最新消息
	const selectUserMessage = async (dataMsg : DATA_MSG) => {
		const res = await request_post_user_newMessage(dataMsg)
		console.log(res, "| res");
		initMsgData.selectUserData = res?.data
	}
	
	//更新为已读状态
	const updateMessageStatusIsRead = async (msgId : number) => {
		return await request_post_update_msgStatus(msgId)
	}
	
	return {
		delMessageById,
		selectAllMessage,
		selectUserMessage,
		updateMessageStatusIsRead,
		initMsgData,
	}
})